package com.ruoyi.myplayer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.myplayer.domain.PlayerPlaylistItem;
import com.ruoyi.myplayer.service.IPlayerPlaylistItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 歌单列表Controller
 * 
 * @author ruoyi
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/myplayer/playitem")
public class PlayerPlaylistItemController extends BaseController
{
    @Autowired
    private IPlayerPlaylistItemService playerPlaylistItemService;

    /**
     * 查询歌单列表列表
     */
    @PreAuthorize("@ss.hasPermi('myplayer:playitem:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlayerPlaylistItem playerPlaylistItem)
    {
        startPage();
        List<PlayerPlaylistItem> list = playerPlaylistItemService.selectPlayerPlaylistItemList(playerPlaylistItem);
        return getDataTable(list);
    }

    /**
     * 导出歌单列表列表
     */
    @PreAuthorize("@ss.hasPermi('myplayer:playitem:export')")
    @Log(title = "歌单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlayerPlaylistItem playerPlaylistItem)
    {
        List<PlayerPlaylistItem> list = playerPlaylistItemService.selectPlayerPlaylistItemList(playerPlaylistItem);
        ExcelUtil<PlayerPlaylistItem> util = new ExcelUtil<PlayerPlaylistItem>(PlayerPlaylistItem.class);
        util.exportExcel(response, list, "歌单列表数据");
    }

    /**
     * 获取歌单列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('myplayer:playitem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(playerPlaylistItemService.selectPlayerPlaylistItemById(id));
    }

    /**
     * 新增歌单列表
     */
    @PreAuthorize("@ss.hasPermi('myplayer:playitem:add')")
    @Log(title = "歌单列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlayerPlaylistItem playerPlaylistItem)
    {
        return toAjax(playerPlaylistItemService.insertPlayerPlaylistItem(playerPlaylistItem));
    }

    /**
     * 修改歌单列表
     */
    @PreAuthorize("@ss.hasPermi('myplayer:playitem:edit')")
    @Log(title = "歌单列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlayerPlaylistItem playerPlaylistItem)
    {
        return toAjax(playerPlaylistItemService.updatePlayerPlaylistItem(playerPlaylistItem));
    }

    /**
     * 删除歌单列表
     */
    @PreAuthorize("@ss.hasPermi('myplayer:playitem:remove')")
    @Log(title = "歌单列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(playerPlaylistItemService.deletePlayerPlaylistItemByIds(ids));
    }
}
